package com.snowy.hidden.user.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.snowy.hidden.user.domain.model.SysRelation;
import com.snowy.hidden.user.mapper.SysRelationMapper;
import com.snowy.hidden.user.service.SysRelationService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 关系(SysRelation)表服务实现类
 *
 * @author makejava
 * @since 2023-11-30 00:28:25
 */
@Service("sysRelationService")
public class SysRelationServiceImpl extends ServiceImpl<SysRelationMapper, SysRelation> implements SysRelationService {


    @Override
    public List<String> getRelationTargetIdListByObjectIdAndCategory(String objectId, String category) {
        return this.getRelationListByObjectIdAndCategory(objectId, category).stream()
                .map(SysRelation::getTargetId).collect(Collectors.toList());
    }

    public List<SysRelation> getRelationListByObjectIdAndCategory(String objectId, String category) {
        LambdaQueryWrapper<SysRelation> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(SysRelation::getObjectId, objectId);
        if (ObjectUtil.isNotEmpty(category)) {
            lambdaQueryWrapper.eq(SysRelation::getCategory, category);
        }
        return this.list(lambdaQueryWrapper);
    }
}
